<?php
class Mcatalogue extends CI_Model{
	protected $_table="tpt_catalogue";
    protected $_table_2="tpt_section";
	public function __construct(){
		parent::__construct();	
		$this->load->database();
	} 	

	public function listCatalogue($arrCol){
        $this->db->select(implode(',',$arrCol));
        $this->db->from($this->_table.' as a');
        $this->db->join($this->_table_2.' as b','a.sec_id = b.id','left');
        return $this->db->get()->result_array();    
    }

    public function list_all(){
        return $this->db->get($this->_table)->result_array();
    }

    public function insert($data){
        $this->db->insert($this->_table,$data);
    }

    public function get_data($id){
        $this->db->where('id',$id);
        return $this->db->get($this->_table)->row_array();
    }

    public function update($data,$id){
        $this->db->where('id',$id);
        $this->db->update($this->_table,$data);
    }

    public function delete($id){
        $this->db->where('id',$id);
        $this->db->delete($this->_table,$data);
    }

    public function list_all_by_sec_id($id){
        $this->db->select('a.id, a.title, a.url');
        $this->db->from($this->_table.' as a');
        $this->db->join($this->_table_2.' as b','a.sec_id = b.id','left');
        $this->db->where("a.sec_id", $id);
        return $this->db->get()->result_array();    
    }
}